package com.nbgs.demo.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nbgs.demo.common.Result;
import com.nbgs.demo.controller.form.BillMessage;
import com.nbgs.demo.service.WaterBillService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j
@CrossOrigin("*")
public class WaterBillController {
    @Autowired
    private WaterBillService waterBillService;

   //动态sql来展示给前端页面信息
    @GetMapping("showBill")
    public Result showBill(@RequestParam(defaultValue = "1")int currPage, @RequestParam(defaultValue = "10")int pageSize,@RequestParam String areaName){
        log.info("分页展示账单{}{}{}",currPage,pageSize,areaName);
        Page<BillMessage> pageParm = new Page<>();
        pageParm.setCurrent(currPage);
        pageParm.setSize(pageSize);
        pageParm.setTotal(waterBillService.getTotal(areaName));
        IPage<BillMessage> all =waterBillService.showSum(pageParm,areaName);
        List<BillMessage> records = all.getRecords();
        for(BillMessage b:records){
            b.setTotals(b.getPayable()+b.getOverdue());
        }
        return Result.success(all);
    }


}
